using System;
using System.Web.Mvc;
using TestBat.Frontend.Controllers.ViewData.Result;
using TestBat.Frontend.Helpers;
using TestBat.IModels.Domain;
using TestBat.IModels.Models;
using TestBat.IModels.Services;

namespace TestBat.Frontend.Controllers
{
    public class ResultController : Controller
    {
        public ResultController(ITestModel testModel, IResultsService resultsService)
        {
            this.resultsService = resultsService;
            this.testModel = testModel;
        }

        public ActionResult Details(Guid testID)
        {
            DetailsViewData vd = new DetailsViewData();

            // get test
            ITest test = testModel.GetByID(testID);

            if (test == null || !AuthenticationHelper.Check(test.Trainee, User))
                throw new ArgumentException("Invalid testID");

            vd.Results = resultsService.GetResults(test);

            vd.Schedule = test.Schedule;

            return View(vd);
        }

        private readonly IResultsService resultsService;
        private readonly ITestModel testModel;
    }
}
